package com.soujiayi.util;

import java.io.File;
import android.content.Context;
 
public class FileCache {
     
    private File cacheDir;
    
    public FileCache(Context context){
        //��һ����������ͼƬ��·��
        if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
            cacheDir=new File(android.os.Environment.getExternalStorageDirectory(),Constants.CACHE_DIR);
        else
            cacheDir=context.getCacheDir();
        if(!cacheDir.exists())
            cacheDir.mkdirs();
    }
     
    public File getFile(String url){

        String filename=String.valueOf(url.hashCode());
        File f = new File(cacheDir, filename);
        return f;
         
    }
     
    public String clear(){
    	String size = CommonUtils.FormatFileSize(CommonUtils.getFileSize(cacheDir));
        File[] files=cacheDir.listFiles();
        if(files == null)
            return "0M";
        for(File f:files)
            f.delete();
        return size;
    }
 
}